Browser

public interface Browser implements Closeable, Advisable<P>, Observable<T>

A web browser control that allows loading a web page or a local HTML file, accessing DOM and executing JavaScript on the loaded web page, getting notifications about loading progress, dispatching keyboard and mouse events, etc.

The Browser instance itself is running in a separate native process that allocates memory and system resources that must be released. So, when a Browser instance is no longer needed, it must be closed through the close method to release all the allocated memory and system resources. For example:

Browser browser = engine.newBrowser();
...
browser.close();

Any attempt to use an already closed Browser instance will lead to the IllegalStateException.

The Browser instance is closed automatically when its Engine is closed or unexpectedly crashed. If the instance represents a popup window created by JavaScript via the window.open() function, then JavaScript can close the instance using the window.close() function.

To get notifications that the Browser instance has been closed please subscribe to the following event:


browser.on(BrowserClosed.class, event -> {
    // The Browser instance has been closed.
});

Functions

Link copied to clipboard
public abstract Audio audio()
Returns Audio that allows controlling audio on a web page loaded in the current browser instance.
Link copied to clipboard
public abstract Bitmap bitmap()
Returns a Bitmap that contains the image of the currently loaded web page.
Link copied to clipboard
public abstract List<CaptureSession> captureSessions()
Returns an immutable list of all active capture sessions initiated by the browser.
Link copied to clipboard
public abstract CompletableFuture<CastSession> cast(MediaReceiver receiver)
Starts casting the browser content to the media receiver.
Link copied to clipboard
Starts casting screen's content by selecting the screen in the picker dialog.
Starts casting the screen's content to the media receiver.
Link copied to clipboard
public abstract void close()
Closes the current browser instance and releases all allocated resources.
public abstract void close(CloseOptions options)
Closes the current browser instance according to the given options.
public abstract void close()
Link copied to clipboard
Returns the default JavaScript PresentationRequest specified on the page.
Link copied to clipboard
public abstract DevTools devTools()
Returns DevTools that allows working with Chromium Developer Tools.
Link copied to clipboard
public abstract void dispatch(KeyPressed event)
Dispatches the key pressed event to the currently focused element on the loaded web page.
public abstract void dispatch(KeyReleased event)
Dispatches the key released event to the currently focused element on the loaded web page.
public abstract void dispatch(KeyTyped event)
Dispatches the key typed event to the currently focused element on the loaded web page.
public abstract void dispatch(MouseDragged event)
Dispatches the mouse dragged event to the currently loaded web page.
public abstract void dispatch(MouseEntered event)
Dispatches the mouse entered event to the currently loaded web page.
public abstract void dispatch(MouseExited event)
Dispatches the mouse exited event to the currently loaded web page.
public abstract void dispatch(MouseMoved event)
Dispatches the mouse moved event to the currently loaded web page.
public abstract void dispatch(MousePressed event)
Dispatches the mouse pressed event to the currently loaded web page.
public abstract void dispatch(MouseReleased event)
Dispatches the mouse released event to the currently loaded web page.
public abstract void dispatch(MouseWheel event)
Dispatches the mouse wheel event to the currently loaded web page.
public abstract void dispatch(TouchCanceled event)
Dispatches the touch canceled event to the currently loaded web page.
public abstract void dispatch(TouchEnded event)
Dispatches the touch ended event to the currently loaded web page.
public abstract void dispatch(TouchMoved event)
Dispatches the touch moved event to the currently loaded web page.
public abstract void dispatch(TouchStarted event)
Dispatches the touch started event to the currently loaded web page.
Link copied to clipboard
public abstract Display display()
Returns the display where the current browser instance is located.
Link copied to clipboard
public abstract Engine engine()
Returns the engine instance of the current browser.
Link copied to clipboard
public abstract Bitmap favicon()
Returns a Bitmap that contains the favicon of the currently loaded web page or a Bitmap that contains default Chromium favicon if the browser did not load any web pages or loaded web page URL is invalid.
Link copied to clipboard
public abstract void focus()
Tells the current browser instance that it has focus and must be activated.
Link copied to clipboard
public abstract Optional<Frame> focusedFrame()
Returns an Optional that contains the focused Frame on the currently loaded web page, otherwise an empty Optional.
Link copied to clipboard
public abstract List<Frame> frames()
Returns all the frames on the currently loaded web page or an empty collection if the current browser did not load any web pages.
Link copied to clipboard
public abstract FullScreen fullScreen()
Returns the service that controls the fullscreen mode.
Link copied to clipboard
public abstract Optional<C> get<C extends P>(Class<C> callbackClass)
Returns an Optional that contains the callback of the given type or an empty Optional if there is no registered callback with the given type.
Link copied to clipboard
public abstract boolean isClosed()
Returns true if the current object is closed.
Link copied to clipboard
public abstract Optional<Frame> mainFrame()
Returns an Optional that contains the main Frame of the currently loaded web page if it exists, otherwise an empty Optional.
Link copied to clipboard
public abstract Navigation navigation()
Returns Navigation that allows controlling navigation in the current browser instance.
Link copied to clipboard
public abstract Subscription on<E extends T>(Class<E> eventClass, Observer<E> observer)
Subscribes the given event observer to receive the events of the given eventClass.
Link copied to clipboard
public abstract Profile profile()
Returns the profile that the browser belongs to.
Link copied to clipboard
public abstract C remove<C extends P>(Class<C> callbackClass)
Removes a particular service callback.
Link copied to clipboard
public abstract void replaceMisspelledWord(String word)
Replaces misspelled word under cursor on the currently loaded web page with the given word.
Link copied to clipboard
public abstract void resize(Size size)
Updates size of the current browser instance with the given one.
public abstract void resize(int width, int height)
Updates size of this Browser instance with the given width and height.
Link copied to clipboard
public abstract boolean saveWebPage(Path htmlFilePath, Path resourcesDir, SavePageType saveType)
Initiates the saving process of the currently loaded web page.
Link copied to clipboard
public abstract C set<C extends P>(Class<C> callbackClass, C callback)
Sets a particular service callback.
Link copied to clipboard
public abstract BrowserSettings settings()
Returns BrowserSettings that allows configuring the current browser instance.
Link copied to clipboard
public abstract Size size()
Returns the size of the current browser instance in the logical pixels.
Link copied to clipboard
public abstract TextFinder textFinder()
Returns TextFinder that allows finding text on a web page loaded in the current browser instance.
Link copied to clipboard
public abstract String title()
Returns a string that represents the title of the currently loaded web page or an empty string if the browser hasn't loaded any web page yet.
Link copied to clipboard
public abstract void unfocus()
Tells the current browser instance that it does not have focus and must be deactivated.
Link copied to clipboard
public abstract String url()
Returns a string that represents URL of the currently loaded web page or an empty string if the browser hasn't loaded any web page yet.
Link copied to clipboard
public abstract String userAgent()
Returns a string that represents the user-agent of the current browser instance.
public abstract void userAgent(String userAgent)
Updates the user-agent string of the current browser instance and reloads the currently loaded web page.
Link copied to clipboard
public abstract Zoom zoom()
Returns Zoom that allows zooming content of a web page loaded in the current browser instance.